package view;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.io.Serializable;

/**
 * Class used as pool: contains all system definitions.
 */
public class Settings implements Serializable
{
	/* User mode */ 
	static public String userMode = UserMode.standartUser;
	
	/* Settings file */
	static private String fileName = "settings";
	
	/********************************* Logger ************************************/
	/* Default depth of the logger in lines */
	protected static final int DEFAULT_LOGGER_WINDOW_DEPTH = 20;
	public static int windowDepth = DEFAULT_LOGGER_WINDOW_DEPTH;
	
	/* Default depth of the logger in days */
	protected static final int DEFAULT_LOGGER_HISTORY_DEPTH = 1;
	
	/* Aclual depth of the logger */
	protected static int historyDepth = DEFAULT_LOGGER_HISTORY_DEPTH;

	/* Option for the last filtering */
	protected static boolean filterOptionNeeded = false;
	protected static String filterOption = null;
	
	/* Parameter for the last filtering */
	protected static boolean filterParameterNeeded = false;
	protected static String filterParameter = null;
	
	public static void save() throws IOException
	{
		/* Open output stream */
		FileOutputStream fos = new FileOutputStream(fileName);
		ObjectOutputStream oos = new ObjectOutputStream(fos);

		/* Save the data */
	    oos.writeObject(Settings.filterOption);
	    oos.writeObject(new Boolean(Settings.filterOptionNeeded));
	    oos.writeObject(Settings.filterParameter);
	    oos.writeObject(new Boolean(Settings.filterParameterNeeded));
	    oos.writeObject(new Integer(Settings.historyDepth));
	      
		/* Close output stream */	    
	    oos.flush();
	    oos.close();
	    fos.close();
	}
	
	public static void load() throws IOException, ClassNotFoundException
	{
		/* Open input stream */
		FileInputStream fis = new FileInputStream(fileName);
		ObjectInputStream ois = new ObjectInputStream(fis);

		/* Save the data */
		Settings.filterOption = (String) ois.readObject();
		Settings.filterOptionNeeded = ((Boolean)ois.readObject()).booleanValue();
		Settings.filterParameter = (String) ois.readObject();
		Settings.filterParameterNeeded = ((Boolean)ois.readObject()).booleanValue();
		Settings.historyDepth = ((Integer)ois.readObject()).intValue();
	      
		/* Close output stream */
		ois.close();
		fis.close();	
	}
}
